import Vue from 'vue'
// 引入基础css样式
import 'normalize.css/normalize.css' // A modern alternative to CSS resets
// 引入elementUI
import ElementUI from 'element-ui'
// 引入elementUI样式
import 'element-ui/lib/theme-chalk/index.css'
// 引用elementUI语言包
// import locale from 'element-ui/lib/locale/lang/en' // lang i18n
// 引用全局样式
import '@/styles/index.scss' // global css

import App from './App'
import store from './store'
import router from './router'

import * as directives from '@/directive'
// 导入语言封装的js文件
import i18n from '@/lang'
// console.log(directives, 'directives')
// console.log(Object.keys(directives)) // ['imgerror', 'focus']

Object.keys(directives).forEach((key) => {
  Vue.directive(key, directives[key])
})
// console.log(process.env)
// console.log(process.env.NODE_ENV)
// if (process.env.VUE_APP_NUM > 900) {
//   console.log('开发环境')
// } else {
//   console.log('生产环境')
// }
// 字体图标
import '@/icons' // icon
// 权限控制的代码
import '@/permission' // permission control
// 组件全局注册
// import PageTools from '@/components/PageTools'
// Vue.component('PageTools', PageTools)
import Components from './components'
Vue.use(Components)
// 注册一个全局自定义指令 `v-allow`
Vue.directive('allow', {
  inserted: function(el, binding) {
    // 从vuex中取出points,
    const points = store.state.user.userInfo.roles.points
    // 如果points有binding.value则显示
    if (points.includes(binding.value)) {
      // console.log('判断这个元素是否会显示', el, binding.value)
    } else {
      el.parentNode.removeChild(el)
      // el.style.display = 'none'
    }
  }
})
/**
 * If you don't want to use mock-server
 * you want to use MockJs for mock api
 * you can execute: mockXHR()
 *
 * Currently MockJs will be used in the production environment,
 * please remove it before going online ! ! !
 */
//  引入 mock的相关配置
// if (process.env.NODE_ENV === 'production') {
//   const { mockXHR } = require('../mock')
//   mockXHR()
// }

// set ElementUI lang to EN
// Vue.use(ElementUI, { locale })
// 如果想要中文版 element-ui，按如下方式声明
Vue.use(ElementUI)

Vue.config.productionTip = false

new Vue({
  el: '#app',
  router,
  store,
  i18n,
  render: h => h(App)
})
